import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import * as THREE from 'three';
const loader = new GLTFLoader();
const model = new THREE.Group();

const spriteMaterial = new THREE.SpriteMaterial({
  transparent: true,

});
const sprite = new THREE.Sprite(spriteMaterial);

let resolveModelLoaded: (value: THREE.Group) => void;
export const modelLoaded = new Promise<THREE.Group>(resolve => {
  resolveModelLoaded = resolve;
});

async function loadModel() {
  try {
    const gltf = await loader.loadAsync("/models/Buletooth.gltf");
    model.add(gltf.scene);
    gltf.scene.scale.set(10, 10, 10);
    gltf.scene.position.set(0, -10, 0);

    model.castShadow = true;
    model.receiveShadow = true;

    resolveModelLoaded(model);

  } catch (error) {
    console.error('模型加载失败:', error);
  }
}

document.addEventListener('DOMContentLoaded', () => {
  // model.add(sprite);
  // sprite.scale.set(50, 50,50);
  // sprite.position.set(0,150, 0);
  loadModel();
});

export { model };